from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

old_password_counselor = [
    {"value": "counselor", "description": "咨询师正确的原密码"},
    {"value": "errorPassword", "description": "咨询师错误的原密码"},
]

new_password_counselor = [
    {"value": "", "description": "咨询师新密码为空"},
    {"value": "counselor", "description": "咨询师新密码与原密码相同"},
    {"value": "new_counselor", "description": "咨询师新密码与原密码不同"},
]

cookie_counselor = [
    {"value": Cookie.COUNSELOR_COOKIE.value, "description": "咨询师登录"},
]

old_password_supervisor = [
    {"value": "supervisor", "description": "咨询师正确的原密码"},
    {"value": "errorPassword", "description": "咨询师错误的原密码"},
]

new_password_supervisor = [
    {"value": "", "description": "督导新密码为空"},
    {"value": "supervisor", "description": "督导新密码与原密码相同"},
    {"value": "new_supervisor", "description": "督导新密码与原密码不同"},
]

cookie_supervisor = [
    {"value": Cookie.SUPERVISOR_COOKIE.value, "description": "督导登录"},
]



def case17_user_password(api_type):
    json_result = {}
    parameters = [
        [old_password_counselor, new_password_counselor, cookie_counselor],
        [old_password_supervisor, new_password_supervisor, cookie_supervisor]
    ]

    i = 0
    for parameter in parameters:
        for pairs in AllPairs(parameter):
            case = template_case()
            request = case["request"]

            # 设置请求体参数
            request["body"]["oldPassword"] = pairs[0]
            request["body"]["password"] = pairs[1]
            # 设置请求体cookie
            request["headers"]["Cookie"] = pairs[2]

            json_result[i] = case
            i += 1

    write_json(api_type.value[0]["file_name"], json_result)
